Attiny85 with DHT22 + 433MHZ transmitter/receiver

Hello Arduino-Community,

I am fascinated to programm smaller things with Arduino and read some threads threats in this forum. My programmer is an Arduino Mega 2560 and want to start now with programm stand alone projects with some Attiny85 chips. Everything looks good - the blink example works well - also the heart beat. But below code isn’t working - compiled with zero errors - but I get no result on the receiver! Also the led isn’t flashing on/out, the led is permanently on?

Can someone check if I have an mistake in my code? Other examples like this example are working pretty well:
http://fluuux.de/2013/12/einfuhrung-in-umgang-mit-einem-433mhz-funkmodul/

I use following libary for the DHT22:
http://playground.arduino.cc/Main/DHTLib

Sketch for transmitter with Attiny85

#include <dht.h>
dht DHT;
#define DHT22_PIN 0
#define DHTTYPE DHT22

#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round
 
const int rxPin     = 2;
const int ledPin    = 3;
 
char *message;
 
void setup()
{
  //Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_tx_pin(rxPin);
}
 
void loop()
{
  uint32_t start = micros();
  int chk = DHT.read22(DHT22_PIN);
  uint32_t stop = micros();

  //Serial.println(DHT.temperature);
  char test[12];
  dtostrf((DHT.temperature,1),3,2,test);
  message = test;

  vw_send((uint8_t *)message, strlen(message)); 
  vw_wait_tx();                                 
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(3000); 
}

Sketch for receiver on Arduino Mega

#include <VirtualWire.h>
 
boolean DEBUG = true;
 
int ledPin = 13;
int rxPin = 8;
 
void setup()
{
  if(DEBUG)
  {
    Serial.begin(9600); 
    Serial.println(F("Arduino startet...")); 
  }
 
  pinMode(ledPin, OUTPUT);
 
  vw_setup(2000);   
  vw_set_rx_pin(rxPin);
  vw_rx_start();
  if(DEBUG) Serial.println(F("RF Verbindung gestartet"));
}
 
void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
 
  char SensorDataTemp[VW_MAX_MESSAGE_LEN+1];           
  String SensorData;                                   
 
  if(vw_get_message(buf, &buflen))
  {
    memset(SensorDataTemp, 0, VW_MAX_MESSAGE_LEN+1); 
 
    for (int i = 0; i < buflen; i++)
    {
      SensorDataTemp[i] = (char)buf[i];
      if(DEBUG) Serial.println("t");
    }
 
    SensorDataTemp[VW_MAX_MESSAGE_LEN+1] = '\0';       
  
  }
  Serial.println(SensorDataTemp);
  Serial.println("test");
  delay(2000);
}

VirtualWire does use a bit of memory -- something like 200 bytes. On an ATTINY85 you could be running out. Does your sketch work on an UNO or Mega? If so, memory would be my guess.

VirtualWire works better with 8mhz. What are you using, 1mhz or 8mhz osc, external or internal?

I am fascinated to programm smaller things with Arduino and read some threats in this forum.

Has anyone made any threats ?

My programmer is an Arduino Mega 2560 and want to start now with programm stand alone projects with some Attiny85 chips.

FYI,

The above should read "My uC is an Arduino Mega 2560 and want to start now with stand alone projects using an ATtiny85 . Research your project with Google before posting on the forum. We are supposed to be your LAST resort or Project Guidance counselors. You don't need project guidance. You need to do some research. Everything you need to know is already on the net and been discussed extensively on the forum and elsewhere. The benchmark tutorial is from MIT. Try using Google. https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1GPCK_enUS504US504&ion=1&espv=2&ie=UTF-8#q=arduino+as+isp+attiny

@Gardner: This could be an reason - or is this the reason. I tested it with my Arduino Nano and it worked (see attached Com5 protocol). If this should be the reason, do you see any option to make code smaller/better? I only want to transmit temperature data.

@Mart: I have set the Attiny85 already to 8MHZ

Thank you so much for your help on this.

@Raschmell: No, sorry. Threads should be correct XD

pcom5.png

Try this attiny core (for Arduino IDE 1.0.5)

https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip

My programmer is an Arduino Mega 2560 and want to start now with programm stand alone projects with some Attiny85 chips.

FYI,

The above should read "My uC is an Arduino Mega 2560 and want to start now with stand alone projects using an ATtiny85 . Research your project with Google before posting on the forum. We are supposed to be your LAST resort or Project Guidance counselors. You don't need project guidance. You need to do some research. Everything you need to know is already on the net and been discussed extensively on the forum and elsewhere. The benchmark tutorial is from MIT. Try using Google. https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1GPCK_enUS504US504&ion=1&espv=2&ie=UTF-8#q=arduino+as+isp+attiny

@raschemmel: I know people like you... and I definitly have searched since yesterday evening (also in this forum). I think this forum is an community were people help other people to get project working. If I have posted this in the wrong section I am sure that an mod will change this.

it is in the right section.

mart256: Try this attiny core (for Arduino IDE 1.0.5)

https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip

Thank you Mart, but I am still working with the attiny core. I have tried to delete all comments within the VirtualLibary (before I have saved the old version ;) ), but it seems that the sketch + both libaries (VirtualLibary and DHTlib) is too large for the Attiny85 chip. Maybe there is somewhere out there who has worked at the same and have an idea to get this working? :drooling_face:

There is not much easy to trim out of the Virtual Wire library they way its built right now. One possibility is to edit VirtualWire.h and change #define VW_MAX_MESSAGE_LEN to a smaller value. It includes some overheads but if you say you can get away with 4 byte messages, you can try 10 instead of the default 30.

Virtual wire -- at least up to VirtualWire.cpp,v 1.9 2013/02/14 -- uses RAM for several things that aught to be PROGMEM, but changing that would be some trouble. Splitting out send from receive is not super beneficial since nearly all of the text and data is referenced directly or indirectly through the interrupt handler, and therefore there is little optimization at link time.

It should be possible to get the BSS size down to about 150 in the transmit- only or receive-only case. One quick win is to put symbols[] and _timer_calc. prescalers[] in pgmspace. The prescalers[] one is particularly insidious because it hits both the BSS and the stack frame for a total impact of 28 bytes.

Before messing with any of this, I recommend ensuring that memory is the issue by debugging on an AVR with more memory. Also do a verbose build with one of the minimal cores and see what the avr-size says. Worrying about memory may be a red-herring.

You need to start simple by verifying radio operation by itself . If you cannot send a signal between your arduinos what point is it to include the DHT22. You have multiple libraries and you don't know if there are conflicts. Try the simplest VirtualWire example with NOTHING else CONNECTED.

I don’t have a DHT22 but a DHT11, but I don’t think that makes any difference.

This sketch works for me on ATtiny 85

I use this core:

https://code.google.com/p/arduino-tiny/

#include <dht.h>

dht DHT;
#define DHT11_PIN 3
#define DHTTYPE DHT11

#include <VirtualWire.h>
const int txPin     = 4;
char *message;

void setup()
{
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_tx_pin(txPin);
}

void loop()
{
  uint32_t start = micros();
  int chk = DHT.read11(DHT11_PIN);
  uint32_t stop = micros();

  char buffer[20];
  int temp=(100*DHT.temperature);
  sprintf (buffer, "temp=%04i",temp );

  vw_send((uint8_t *)buffer, strlen(buffer)); 
  vw_wait_tx();                                 
  delay(3000); 
}

Edit: bug corrected

This sketch works for me on ATtiny 85

mpiled with zero errors - but I get no result on the receiver! Also the led isn't flashing on/out, the led is permanently on?

So what are you saying ? Are you saying you can send and receive a radio signal without the DHT11 ? (That the radio is working...)

I think that Virtualwire and the DHT11/22 need to use timers, and wont work if they use the same timers. You need to check the DHT and the Virtualwire libraries to see what timers are used.

So what are you saying ?

I am saying that you can use DHT library and VirtualWire library on t85 at the same time, in this example t85 as transmitter and UNO as receiver,

There was a minor bug in the sketch I uploaded, that is now corrected

Erni:
I don’t have a DHT22 but a DHT11, but I don’t think that makes any difference.

This sketch works for me on ATtiny 85

I use this core:

https://code.google.com/p/arduino-tiny/

#include <dht.h>

dht DHT;
#define DHT11_PIN 3
#define DHTTYPE DHT11

#include <VirtualWire.h>
const int txPin     = 4;
char *message;

void setup()
{
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_tx_pin(txPin);
}

void loop()
{
  uint32_t start = micros();
  int chk = DHT.read11(DHT11_PIN);
  uint32_t stop = micros();

char buffer[20];
  int temp=(100*DHT.temperature);
  sprintf (buffer, “temp=%04i”,temp );

vw_send((uint8_t *)buffer, strlen(buffer));
  vw_wait_tx();                                 
  delay(3000);
}




Edit: bug corrected

Dear Erni,

At first thank you so much for your help.
I tested your code yesterday night. On my arduino this code runs well, but on the Attiny85 it send (after connecting battery only one Signal “31172” - after this I can reconnect battery to get the same signal. This code on my arduino mega runs without problems, couriously there is the same “31172” output if the DHT22 isn’t on line. I have attached an picture which show the output on my arduino mega if I run this code.

#include <dht.h>

dht DHT;
#define DHT22_PIN 3
#define DHTTYPE DHT22

#include <VirtualWire.h>
const int txPin     = 4;
const int LedPin     = 13;
char *message;

void setup()
{
  Serial.begin(9600);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_set_tx_pin(txPin);
}

void loop()
{
  uint32_t start = micros();
  int chk = DHT.read22(DHT22_PIN);
  uint32_t stop = micros();

  char buffer[20];
  int temp=(100*DHT.temperature);
  sprintf (buffer, "%04i",temp );
  Serial.print("Buffer ");
  Serial.println(buffer);
  vw_send((uint8_t *)buffer, strlen(buffer)); 
  vw_wait_tx();
  digitalWrite(LedPin, HIGH);
  delay(1000);
  digitalWrite(LedPin, LOW); 
  delay(2000);
}

pcom4.png

Dear Erni,

Arrgg. :disappointed_relieved: :grin:
I downloaded once again the attiny core and now it runs. Don’t ask me what core I had before - I was sure to work with the same you posted - but it seems that this was an mistake.
You can see below the output on my receiver. There are some strange outputs sometimes, but I am sure I can get this under control. :wink:

Thank you so much that you helped me. Now I can go ahead.
Enjoy your weekend. :slight_smile: