Hi,
After trying too much times, wasting too much hours, i came to the conclusion that i need to ask some help here.
I have an Arduino Mega2560, and when combined with the DFrobot LCD Keypad Shield I have no problem reading out a HC-SR04 ultrasonic sensor in combination with a DS18B20 temperature sensor.
When I add the Ethernet Shield SD, my sensor doesn't work anymore. I already took the shields apart, and connected the lcd with wires to other pins than those on the ethernet shield. No solution.
The Ethernet Shield SD : http://datasheet.octopart.com/A000056-Arduino-datasheet-10403576.pdf
The LCD Keypad Shield : Gravity: 1602 LCD Keypad Shield For Arduino - DFRobot
The NewPing library : http://code.google.com/p/arduino-new-ping/
The code :
#include <LiquidCrystal.h>
#include <NewPing.h>
#include <OneWire.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define TRIGGER_PIN 40
#define ECHO_PIN 41
#define MAX_DISTANCE 300
OneWire ds(39);
// pin 11 is de 4de pin van rechts boven de lcd op het lcd keypad shield
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int DistanceIn;
int DistanceCm;
int Getal;
byte five[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
byte four[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
};
byte three[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
};
byte two[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
};
byte one[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
};
byte none[8] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte grad[8] = {
B01110,
B01010,
B01110,
B00000,
B00000,
B00000,
B00000,
};
void setup() {
lcd.createChar(0, five);
lcd.createChar(1, four);
lcd.createChar(2, three);
lcd.createChar(3, two);
lcd.createChar(4, one);
lcd.createChar(5, none);
lcd.createChar(6, grad);
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
delay(500);
int barsleft = 16;
int inhoud;
int getal;
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
DistanceCm = sonar.ping_cm();
inhoud = 9540 - ((DistanceCm-31)*45);
getal = inhoud;
if (getal > 9600) getal = 9600;
lcd.setCursor(0,0);
while(inhoud >= 600)
{
if (inhoud >= 600) {
lcd.write(byte(0));
inhoud = inhoud - 600;
barsleft = barsleft - 1;
}
}
while(inhoud >= 480)
{
if (inhoud >= 480) {
lcd.write(byte(1));
inhoud = inhoud - 480;
barsleft = barsleft - 1;
}
}
while(inhoud >= 360)
{
if (inhoud >= 360) {
lcd.write(byte(2));
inhoud = inhoud - 360;
barsleft = barsleft - 1;
}
}
while(inhoud >= 240)
{
if (inhoud >= 240) {
lcd.write(byte(3));
inhoud = inhoud - 240;
barsleft = barsleft - 1;
}
}
while(inhoud >= 120)
{
if (inhoud >= 120) {
lcd.write(byte(4));
inhoud = inhoud - 120;
barsleft = barsleft - 1;
}
}
while(barsleft >= 1)
{
lcd.write(byte(5));
barsleft = barsleft - 1;
}
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr*, HEX);*
-
}*
-
Serial.println();*
-
// the first ROM byte indicates which chip*
-
switch (addr[0]) {*
-
case 0x10:*
-
Serial.println(" Chip = DS18S20"); // or old DS1820*
-
type_s = 1;*
-
break;*
-
case 0x28:*
-
Serial.println(" Chip = DS18B20");*
-
type_s = 0;*
-
break;*
-
case 0x22:*
-
Serial.println(" Chip = DS1822");*
-
type_s = 0;*
-
break;*
-
default:*
-
Serial.println("Device is not a DS18x20 family device.");*
-
return;*
-
}*
ds.reset();
-
ds.select(addr);*
-
ds.write(0x44, 1); // start conversion, with parasite power on at the end*
-
delay(1000); // maybe 750ms is enough, maybe not*
-
// we might do a ds.depower() here, but the reset will take care of it.*
-
present = ds.reset();*
-
ds.select(addr); *
-
ds.write(0xBE); // Read Scratchpad*
Serial.print(" Data = "); -
Serial.print(present, HEX);*
-
Serial.print(" ");*
-
for ( i = 0; i < 9; i++) { // we need 9 bytes*
_ data = ds.read();_
_ Serial.print(data*, HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Convert the data to actual temperature*
* // because the result is a 16 bit signed integer, it should*
* // be stored to an "int16_t" type, which is always 16 bits*
* // even when compiled on a 32 bit processor._
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
_ raw = raw << 3; // 9 bit resolution default*
* if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution*
* raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them*
* if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms*
* else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms*
* else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms*
* //// default is 12 bit resolution, 750 ms conversion time*
* }
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");*_
lcd.setCursor(0,1);
lcd.print(getal);
lcd.print("L ");
if (getal < 1000) lcd.write(" ");
if (getal <= 9600) lcd.write(" ");
lcd.print(celsius);
lcd.print("C");
lcd.write(byte(6));
lcd.write(" ");
}
I tried a lot of different pins, but it didn't work. I read somewhere that there are some pins in common, so i connected the lcd keypad to other pins, and the sensor too.
*Who can guide me ? *
Thanks,
Bart