Attiny85 - 433MHz Tx to send PWM signal to 433Mhz Rx. Best way?

Ok, so on trying to get any form of these 433Mhz tx/rx to work on the Attiny85 ,I think I want to resort to sending a PWM signal through the ATtiny to the TX and receive on a second ATting85 via the RX.
Figured at least I would have 8bit values as opposed to nothing!

Any hints?

These are the tx/rx units I am using:

Forget abiut the Rduino for now. just conne t a swtch to the trabsmitter a d a led to the receivee and do a Go/No-go test.
If that doexn' work then PWM WOULDN'T work.

VirtualWire will work on the ATtiny85, but it takes a bit of effort. See this thread virtual wire and attiny85 - Microcontrollers - Arduino Forum and others on the forum.

I am definitely getting a signal. I can send the PWM pulse through the ATtiny85 and the TX and getting a similar PWM signal out of the RX. Just want a way to measure the PWM frequency on the RX side with an MCU.

Look up " PulseIn" funcion.
Do you how to make the Tx & Rx antennas ?

Don't waste time trying to send a PWM signal from one Arduino to another. Just send a byte (0-255) and let the receiving Arduino generate the PWM signal.

...R

Thanks very much :).

8 bit produced with no real problems. Some fluctuation from noise but for simple systems (maybe 6 bit systems) can easily so things.

int pin = 2;
int duration;

void setup()
{
  pinMode(pin, INPUT);
  Serial.begin(9600);
}

void loop()
{
 duration = pulseIn(pin, LOW);

int value=map(duration,12800,15600,0,1023);
  Serial.println(value);
  delay(100);
}

Ah, I see there is a huge problem with noise actually. Would not have assumed this much noise where I live but sheesh!
Looks like I will have to go down the real coding route :(.

What is the code in Reply #6 trying to do?

If you send a number from one Arduino to the other you can add error detection/correction. Also, you only need to send a number when the PWM needs to change. And the receiving Arduino can keep the PWM going even if some of the received data is invalid.

...R

It was just counting the microseconds between pulses (1->0), converting it in to a value from 0-255 to output to an LED as a visual cue.

Did some very basic error correction and smoothed out noise by taking average of 10 readings:

//Using an Arduino Nano with a 433Mhz Reciever.
//Playing with signal smoothing/noise reduction.




int pin = 2;                   // Reciever in PIN
unsigned long duration;                 // To be used by pulseIn
int n=20;                     // values to take for average
void setup()
{
  pinMode(pin, INPUT);       //Input the reciever in
  pinMode(5, OUTPUT);       // LED output for visual cue
  Serial.begin(9600);       // start serial for debugging
}

void loop()
{
 int x=0;                       // start a counter
 int sum=0;                     // declare "sum of values"
  float array[100];             // declare a 100 array
  while(x<n){                   // Take 10 values in a row...
 duration = pulseIn(pin, LOW);   // values taken from pulseIn
float value=map(duration,12800,15600,1023,0); // Map them to 10bit

if (value<0){}                   //if the value is <0 (i.e. weak signal...dump it
else{                            //add the values up in to int sum.
array[x]=value;
sum=sum+array[x];
x++;
  }}
int average=sum/n;               // divide sum by 10 to get average.

if (average<15){}
else{
Serial.print(average);
Serial.print("                ");
}

if (average<15){               // if negative value (weak signal)...dump.
  
  
  analogWrite(5, 0);
  Serial.print("Average is less than 15...it is    ");
  Serial.println(average);
}                   
else{                              //otherwise set map value to 8 bit PWM for LED output.
  int pwm_led = map(average,0,1023,0,255);
  analogWrite(5, pwm_led);
  

Serial.println(pwm_led);
delay(100);
}
}

You should not constantly send PWM or anything else with these modules, as it will interfere with other users of the 433mhz e.g your neighbours or other wireless devices you have in your house.

There is an approved duty cycle for the 433mhz ism band, you need to check your design does not exceed this usange

Ah, I see there is a huge problem with noise actually.

No surprise there. That is why libraries like VirtualWire were written. You are simply wasting your time with the PWM approach.

raschemmel:
Forget abiut the Rduino for now. just conne t a swtch to the trabsmitter a d a led to the receivee and do a Go/No-go test.
If that doexn' work then PWM WOULDN'T work.

check out this link. might help.

http://tinyurl.com/828tt5r

I have to say thanks to all in this thread.
I finally got VirtualWire working. The last porblem I seem to be having is the whole int->char char->int conversion. Getting extra digits and kinda wondering why is there not an actual standalone "send integer" option in the library.

The TX:

// 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>

void setup()
{
    //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()
{
    
    int value=1; 
    char msg[5];
    while (value<1024){       //Count to 1024
    itoa(value,msg,5);      //Convert int to char
    digitalWrite(1, HIGH);     // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg)); // send the char (msg)
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(1,LOW);
    delay(1000);
    value++;} //add 1 to value and repeat.
}

The RX

// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

void setup()
{
    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_rx_pin(2);
    vw_rx_start();       // Start the receiver PLL running
   
}

void loop()
{
   char recieved_msg[5];
   int recieved_int;
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking

    {
	int i;

        digitalWrite(13, true); // Flash a light to show received good message
	// Message with a good checksum received, dump it.
	Serial.print("Got: ");
	
	for (i = 0; i < buflen; i++)
	{
  
	    recieved_msg[i]=char(buf[i]);
	}
recieved_int=atoi(recieved_msg);
	Serial.println(recieved_int);
        digitalWrite(13, false);
    }
}

You can send anything you wish (up to about 34 bytes in one packet -- check the documentation at VirtualWire: VirtualWire.h File Reference). Try something like the following

int junk = 26;
vw_send((uint8_t *)junk, 2); // send the integer variable

jremington:
You can send anything you wish (up to about 34 bytes in one packet -- check the documentation at VirtualWire: VirtualWire.h File Reference). Try something like the following

int junk = 26;

vw_send((uint8_t *)junk, 2); // send the integer variable

Yeah I assumed I would be being daft. Think I am not setting the Rx code to correctly read the Tx data:

TX:

int value=26; 
        while (value<1024){       //Count to 1024
         

    vw_send((uint8_t *)value, 4); // send the char (msg)
    vw_wait_tx(); // Wait until the whole message is gone
    
    delay(1000);
    value++;} //add 1 to value and repeat.

RX code:

if (vw_get_message(buf, &buflen)) // Non-blocking
    {
	int i;
	// Message with a good checksum received, dump it.
	Serial.print("Got: ");
	
	for (i = 0; i < buflen; i++)
	{
	Serial.print(buf[i],DEC);
	    Serial.print(" ");
	}
	Serial.println("");
     
    }
}

In the following, you should replace the "4" with "2", or sizeof(value).

vw_send((uint8_t *)value, 4); // send the char (msg)

On the receiving end, you will have to do something slightly more complicated to reconstruct the integer. There are several ways to do that, but one that I find convenient is to use a union declaration on both ends. This reserves variable space with two or more names and types, which allows you to reference the data in different ways. For example:

// put this "union" declaration in both transmitter and receiver code
union {
  uint8_t bytes[2];
  int intval;
} data

// to send ...
data.intval = 1234;
result = vw_send(data.bytes, sizeof(data));

// to receive
 if (vw_get_message(buf, &buflen)) // Non-blocking
    {
    data.bytes[0]=buf[0]; //copy received bytes into the union
    data.bytes[1]=buf[1];
    Serial.println(data.intval);
   }

On the receiving end, you will have to do something slightly more complicated to reconstruct the integer. There are several ways to do that, but one that I find convenient is to use a union declaration on both ends. This reserves variable space with two or more names and types, which allows you to reference the data in different ways. For example

Thanks again. The code is my weaker point so going to have to do some reading up on "unions". Thanks again!

Sorry, but I just noticed that the first example I posted is missing an "&" (address of) and should read

   int junk = 26;
   vw_send( (uint8_t *) &junk, 2); // send the integer variable

So your example of sending "value" should likewise read

    vw_send( (uint8_t *) &value, sizeof(value) ); // send the char (msg)
    vw_wait_tx(); // Wait until the whole message is gone

The other example, using a union, should be OK, but I don't currently have a setup to test this with VirtualWire. This has come up before in the forum so use the Search function to look for other ways of doing it. For example, you can reconstruct an integer from the first two entries in a character buffer directly, using the following sort of construct:

int value = ( (int) buf[1]<<8  |  buf[0]);

http://www.utopiamechanicus.com/article/data-splitting-union-and-struct-c/