'dht' does not name a type - arduino

I'm running this code and it keeps giving me this error. Below I'm putting the code. It's a weather station arduino code. I already added and imported the libraries but I keep getting the same error.
#include <stdlib.h>
#include <SoftwareSerial.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#define SSID "DroidSpot" //replace XXXXX by your router SSID
#define PASS "gggg" //replace YYYYY by your router password
#define IP "184.106.153.149" // thingspeak.com IP
#define DHT22_PIN 2
String GET = "GET /update?key=GDQ0LAAXLDGYMXW1&field1="; //replace ZZZZZ by your ThingSpeak channel write key
SoftwareSerial monitor(10, 11); //Serial communication to ESP8266 module (RX, TX)
dht DHT;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
.....
//read other sensors
char buffer[10];
//light sensor
float luminance = analogRead(luminancePin);
//UV sensor
float uv = analogRead(uvPin);
uv = uv * 0.0049; //convert values to volts
uv = uv * 307; //convert to mW/m²
uv = uv/200; //calculate UV index
//temperature and humidity
int chk = DHT.read22(DHT22_PIN);
float humidity = DHT.humidity;
float temperature = DHT.temperature;
//pressure and temperature1
sensors_event_t event;
bmp.getEvent(&event);
float pressure = 0;
float temperature1 = 0;
if (event.pressure)
{
pressure = event.pressure;
bmp.getTemperature(&temperature1);
}
The error is in the dht DHT; line. It is:
'dht' does not name a type

Check which library you are using. You might be trying to combine two different source code examples using two different libraries.
The body of your code seems to suggest you want a different library. This library defines the type you want: https://github.com/RobTillaart/DHTstable with the appropriate fields as Juraj has pointed out.
You'll have to change your header(s) as well, as here. Especially:
#include <dht.h>
If you do intend to use the Adafruit library, as your includes seem to suggest:
As the error says, there's no class or type definition for dht. The class name is DHT, not dht.
See DHT.h in the Github repo, and this example in the same repo.
Switch the tokens around:
DHT dht;
and refactor all other DHT to dht. You'll also need to make sure you're calling the right class method, as read22 is not defined in this library.

Related

Arduino: Oled not working when SD library is included

I'm currently trying to put together a datalogger with an OLED screen and am having issues when adding the SD library to the script. I've seen that others have gotten error messages when combining Oled and SD cards that is related to RAM. Though in my case, the code runs, there is no error message, but the screen doesn't display anything. The code below shows the "OLED code" where the Oled display wouldn't show anything when I added the "#include <SD.h>". Also, since I quite new to this, some constructive criticism of the code itself is also welcome
Thanks!
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_MCP9808.h"
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // use I2C interface
Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
//oled definitions
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Address 0x3D for 128x64
// Clear the buffer
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.setTextColor(WHITE);
while (!Serial);
Serial.println("Loading");
if (!tempsensor.begin(0x18)) {
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
while (1);
}
Serial.println(F("Found MCP9808!"));
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
// 2 0.125°C 130 ms
// 3 0.0625°C 250 ms
if (!bme.begin()) {
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
while (1) delay(10);
}
bme_temp->printSensorDetails();
bme_pressure->printSensorDetails();
bme_humidity->printSensorDetails();
}
void loop() {
float temp = bme.readTemperature(); // get temperature in degree Celsius
float humi = bme.readHumidity(); // get humidity in rH%
float pres = bme.readPressure(); // get pressure in Pa
tempsensor.wake();
//Serial.println (tempsensor.getResolution());
float c = tempsensor.readTempC();
float f = tempsensor.readTempF();
//float sensor=analogRead(A4);
display.setCursor(0, 0);
display.print(F("Temp_1: "));
display.print(c,2);display.println(" \tC ");
display.println("");
display.print(F("Temp_2: "));
display.print(temp,2);display.println(" \tC ");
display.println("");
display.print(F("Humidity: "));
display.print(humi,2);display.println(" %RH ");
display.println("");
display.print(F("Pressure: "));
display.print(pres/100,2);display.println(" kPa ");
display.display();
delay(1000);
display.clearDisplay();
Its just memory problem. I fix it by decrease the resolution only for usage area.. Its not the best solution however good enough for me
This was apparently a memory issue.
I've now connected an Arduino Mega instead of a Nano, and the code ran nicely. I've also added the remaining piece of code that was necessary to log the sensor readings.
According to what I've read on other forums, the SD and SPI libraries take up quite a lot of memory.

Write an array of bytes to EEPROM from PROGMEM

I'm trying to store an array of LED patterns to EEPROM, to later write to an external flash module. Below is my header file containing the patterns.
#ifndef DefaultPatterns_h
#define DefaultPatterns_h
#define DEFAULT_SIZE 147
const byte defaultData[DEFAULT_SIZE] PROGMEM ={225,112,111,};
#define RAINBOWPIXEL_SIZE 972
const byte rainbowpixelData[RAINBOWPIXEL_SIZE] PROGMEM ={255,0,0,0,0,0,0};
#endif
I've cut some bytes out from the above patterns as they are too long for this post.
Below is my sketch that is taken from ESP8266 EEPROM example library and I'm trying to use it as a starting point. I've commented out some things I've tried. Remember the patterns are in a header file.
#include "EEPROM.h"
#include "defaultPatterns.h"
int addr = 0;// address of EEPROM to write to
void setup() {
EEPROM.begin(512);
}
void loop() {
Serial.begin(9600);
//const byte defaultData[] = PROGMEM(defaultData,DEFAULT_SIZE );
// write the value to the appropriate byte of the EEPROM.
// these values will remain there when the board is
// turned off.
// EEPROM.write(addr, val);
//EEPROM.write(addr,byte (defaultData)) sizeof(defaultData));
//EEPROM.write ( 0, (byte *)defaultData), sizeof(defaultData)));
const char pattern = defaultData ;
EEPROM.write(addr, pattern);
// advance to the next address. There are 512 bytes in
// the EEPROM, so go back to 0 when we hit 512.
// save all changes to the flash.
addr = addr + 1;
if (addr == 512) {
addr = 0;
EEPROM.commit();
}
delay(100);
}
I've tried all sorts of different ways, but I'm getting errors and syntax errors.
I've tried to do this myself but I'll be at it forever. Any help that would be great.
I'm trying to build a LED controller that can store lots of patterns in the form of the patterns in the header file and play them back via a WS2812B strip of LEDs on button press. I've a long way to go.
Why use flash you ask? Space, I need lots of space. I know flash wears out faster, but I can replace it for a few bucks.
Look at the definition of EEPROM.write() - it only writes one byte. You need to use a for loop or EEPROM.put().

Saving two values into arduino uno EEPROM

I am looking to save pulse and SPO2 readings from the cooking hacks e-health sensor platform (link below) onto my Arduino Uno's EEPROM then remove the health shield and use an Ethernet shield to move the data. A piece of my code is as below:
#include <PinChangeInt.h>
#include <eHealth.h>
#include <EEPROM.h>
int cont =0;
int addr =0;
int BPM;
int SPO2;
void loop() {
Serial.print("PRbpm:");
Serial.print(e.health.getBPM);
BPM =eHealth.getBPM();
Serial.print("%SPo2 :);
Serial.print(eHealth.getOxygenSaturation());
SPO2 =eHealth.getOxygenSaturation();
Serial.print("\n");
Serial.println("===========");
EEPROM.write(0,eHealth.getBPM());
delay(500);
}
The two readings I am trying to save and then load onto another sketch are BPM and SPO2, does the line:
EEPROM.write(0,eHealth.getBPM());
make sense and how would I also save and send the second reading SPO2?
Any help appreciated or any knowledge of why my idea will not work also appreciated, thanks.
Cooking-hacks sensor platform
EEPROM.write(0,BPM);
EEPROM.write(1,SPO2);

RFduinoBLE: Send multiple numbers?

This is probably a very basic question but I have been googleing for hours now and cannot find a solution.
I am trying to send three values from my RFduino to my iPhone which should all three then be displayed on my custom app (very simple). For this I changed the given Temperature app and RFduino code which I found on their GitHub.
But in all the example they only send 1 value over BLE, how can I send multiple without overwriting instantly?
In my code I am trying to do it like this and I also tried arrays, char arrays but nothing worked, at the moment the app only breaks..
my RFduino code looks like this (Minimal example)
#include <Wire.h>
#include <RFduinoBLE.h>
#include "Arduino.h"
int16_t x1,x2,x3;
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("setting up Sensor...");
SetupSensor(); // Configure sensor
delay(1500); //wait for the sensor to be ready
RFduinoBLE.advertisementData = "sensor";
// start the BLE stack
RFduinoBLE.begin();
}
void loop(){
RFduino_ULPDelay( 25 );
getSensorValues(); // sensor update
RFduinoBLE.sendByte(x1);
RFduinoBLE.sendByte(x2);
RFduinoBLE.sendByte(x3);
}
(I am also very confused if I should send Byte or Int or Float and the whole thing with internal conversion..)
The "intresting" part in the app-code is this one:
- (void)didReceive:(NSData *)data
{
NSLog(#"RecievedRX");
float x1 = dataFloat(data);
float x2 = dataFloat(data);
float x3 = dataFloat(data);
NSString* string1 = [NSString stringWithFormat:#"%.2f", x1];
NSString* string2 = [NSString stringWithFormat:#"%.2f", x2];
NSString* string3 = [NSString stringWithFormat:#"%.2f", x3];
[label1 setText:string1];
[label2 setText:string2];
[label2 setText:string3];
}
I KNOW this is completely wrong but I have no idea on how to fix it? Can I just somehow pack my values into an array and sent all by one?

Serial Programming for POSIX, non-standard baud rate

I am implementing a simple program in unix that takes a RS232 input and saves it into a file.
I've used these references:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux and
http://www.easysw.com/~mike/serial/serial.html
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
int main(int argc,char** argv)
{
struct termios tio;
struct termios stdio;
int tty_fd;
fd_set rdset;
FILE *file;
unsigned char c;
memset(&tio,0,sizeof(tio));
tio.c_iflag=0;
tio.c_oflag=0;
tio.c_cflag=CS8|CREAD|CLOCAL; // 8n1, see termios.h for more information
tio.c_lflag=0;
tio.c_cc[VMIN]=1;
tio.c_cc[VTIME]=5;
tty_fd=open("/dev/ttyS1", O_RDWR | O_NONBLOCK);
speed_t baudrate = 1843200; //termios.h: typedef unsigned long speed_t;
cfsetospeed(&tio,baudrate);
cfsetispeed(&tio,baudrate);
tcsetattr(tty_fd,TCSANOW,&tio);
file = fopen("out.raw", "wb");
while (1)
{
if (read(tty_fd,&c,1)>0) {
fwrite(&c, 1, 1, file);
fflush(file);
}
}
//close(tty_fd);
}
I've tried at 921'600 bps and at 1'843'200 bps, and it works correctly.
However, it does not work if I set-up a non-standard baud rate, for instance 1'382'400 bps.
i.e., this works:
cfsetospeed(&tio,1843200); cfsetispeed(&tio,1843200);
but this doesn't (it gets random data):
cfsetospeed(&tio,1382400); cfsetispeed(&tio,1382400);
What can be the problem?
I've tried with WinXP (using the WIN32 functions CreateFile, SetCommState and ReadFile),
and it works correctly (with 1'843'200 bps and also with the non-standard 1'382'400 bps)
ps: if you ask why I need to set-up this non-standard baud-rate, it's because of a special machine that works only at this speed.
Regards,
David
According to mans cfsetospeed accepts macros, B0, B50 , B75 and so on which are not equal to actual baudrate values (B9600 is equal to 15 e.g.). So passing random integer will cause undefined behaviour.
cfsetospeed() sets the output baud rate stored in the termios
structure pointed to by termios_p to speed, which must be one of
these constants: B0, B50 and so on

Resources