Hello
I am trying to use a attiny85 to transmit an one byte int to a arduino Uno r3 using a simple 433mhz transmitter and receiver. I have no idea how to do this. I tried to use the virtualwire library but I couldn't get my arduino didn't receive a response when I used the example code. I know there is a new library called radiohead but I haven't used that. I am new to arduino so please keep it simple.
Thanks
I have hooked up a couple of sensors and used watchdog without a problem:
// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
#include <VirtualWire.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
volatile boolean f_wdt = 1;
void setup()
{
setup_watchdog(9); // approximately 4 seconds sleep
//Serial.begin(9600); // Debugging only
//Serial.println("setup");
// Initialise the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(500); // Bits per sec
vw_set_tx_pin(0); //Transmitter on pin 4 of the ATtiny85
}
void loop()
{
char TSL257_IN=A2;
int PWR=3;
pinMode(TSL257_IN,INPUT);
pinMode(PWR, OUTPUT);
if (f_wdt==1) { // wait for timed out watchdog / flag is set when a watchdog timeout occurs
f_wdt=0; // reset flag
union {
uint8_t bytes[2];
int value;
} data;
digitalWrite(PWR,HIGH);
data.value=analogRead(TSL257_IN);
digitalWrite(PWR,LOW);
data.value=data.value+2000;
vw_send(data.bytes, sizeof(data)); // send the char (msg)
vw_wait_tx(); // Wait until the whole message is gone
system_sleep();
}// if f_wdt check
} // voiud loop
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
f_wdt=1; // set global flag
}