Hi!
Have an arduino one with imp shield that is connected RX/TX numbers 0/1 on the shield. Two sensor one rht03 connected to gnd, 5V and 7 and another moisture sensor connected to A0, 5 and 6. I have two problems, one is that when pushing in the imp the analog readings goes from 0 to 511 and does not respond to changes. Otherwise the respons from that moisture sensor goes from 0-960 between open air and shortcut.
The next hurdle is that I do not seem to be able to read serial data. On a serial sniffer on a computer connected with USB I get readings but using imp I get “No Data Returned” using this code (same UART setting in both):
// UART Read Example
// configure a pin pair for UART TX/RX
hardware.uart12.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS);
function readSerial() {
imp.sleep(0.1);
local result = hardware.uart12.read();
if (result == -1) {
server.show(“No data returned.”);
} else {
server.show(result);
}
imp.wakeup(300, readSerial);
}
imp.configure(“Serial RX”, [], []);
readSerial();
Was not allowed to upload arduino file so post the code here:
// Combination of http://gardenbot.org/howTo/soilMoisture/#The_local_circuit_-_simple_voltage and http://askforcode.blogspot.se/2013/02/interfacing-rht03dht22-temperature-and.html
#include <DHT22.h>
// Data wire is plugged into port 7 on the Arduino
// Connect a 4.7K resistor between VCC and the data pin (strong pullup)
#define voltageFlipPin1 5
#define voltageFlipPin2 6
#define sensorPin 0
#define DHT22_PIN 7
// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);
int flipTimer = 1000;
void setup(){
// start serial port
Serial.begin(19200);
pinMode(voltageFlipPin1, OUTPUT);
pinMode(voltageFlipPin2, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.println(“SENSOR DEMO”);
}
void setSensorPolarity(boolean flip){
if(flip){
digitalWrite(voltageFlipPin1, HIGH);
digitalWrite(voltageFlipPin2, LOW);
}else{
digitalWrite(voltageFlipPin1, LOW);
digitalWrite(voltageFlipPin2, HIGH);
}
}
void loop(){
//
DHT22_ERROR_t errorCode;
Serial.print(“Requesting data…”);
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{
Serial.print("Got Data ");
Serial.print(myDHT22.getTemperatureC());
Serial.print(“C “);
Serial.print(myDHT22.getHumidity());
Serial.println(”%”);
}
else
{
Serial.print(“Error Code “);
Serial.print(errorCode);
Serial.println(” readData Failed”);
}
setSensorPolarity(true);
delay(flipTimer);
int val1 = analogRead(sensorPin);
delay(flipTimer);
setSensorPolarity(false);
delay(flipTimer);
// invert the reading
int val2 = 1023 - analogRead(sensorPin);
//
reportLevels(val1,val2);
}
void reportLevels(int val1,int val2){
int avg = (val1 + val2) / 2;
String msg = "avg: ";
msg += avg;
Serial.println(msg);
}
Any ideas?
Kind regards
Fredrik