Pages: 1 [2]   Go Down
Author Topic: virtual wire and attiny85  (Read 3104 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all for the information, Blinking a message ha, that to me seems hard as i dont know morse code and binary hmmm lol

its still not working and i have no more variations of the password to try so i may need to experiment with some other way smiley-sad

i dont really know much about all this but would the compare between uint8_t and char array have anything to do with it? also the fact its static, i assume when we receive a mesage the static variable changes to the message right?
Logged

Offline Offline
God Member
*****
Karma: 25
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's possible that your problem is here:

Code:
        if (buflen >= sizeof(SECRET_CODE)

The way I calculate it, when the password is "Benson14", sizeof(SECRET_CODE) is 9.  The actual message is only 8 characters long.  if buflen doesn't include the null terminator, 8 won't be >- 9, and the test will fail.  Maybe you should use strlen(SECRET_CODE) or hard code an 8 in there and see if that works.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i dont know morse code and binary

Well, there's your problem...

(Morse code I can excuse, but binary? All programmers should be able to read binary.)
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1058
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i dont know morse code and binary

That's why I recommended using the serial monitor and Serial.print(), like you are used to from the Arduino
Logged

Offline Offline
God Member
*****
Karma: 25
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, that's just a detail.  There are ways to get around any of those issues.

1) Blink it in binary or Morse Code, take a video, and post it where someone who DOES know them can interpret.

2) Blink the raw numbers, with pauses in between.  First, blink the buflen.  Then blink out each of the letters in the msg.  So what if it takes 110 blinks to blink an 'n'?  At least it's SOMETHING.

Trying to debug a problem by staring at the code is sometimes just not going to work.  If you can somehow get the machine to tell you what's actually going on in there, you can figure out what's actually wrong, instead of guessing.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) Blink it in binary or Morse Code, take a video, and post it where someone who DOES know them can interpret.

Build an Arduino morse-code decoder. smiley

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5378
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have good musical pitch you can get it to output tones at different frequencies.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Sr. Member
****
Karma: 9
Posts: 272
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Benson, try this exact code on the sender:
Don't change "SECRET_CODE" yet.

Code:
#include <VirtualWire.h>

#define PIN_TX          2
#define VW_SPEED        2000
#define TX_DELAY        5000

static const SECRET_CODE[] = { 0x01, 0x02, 0x03 }

void setup()
{
    pinMode(PIN_TX, OUTPUT);

    vw_set_ptt_inverted(true); // Required for DR3100    
    vw_setup(VW_SPEED);
    vw_set_tx_pin(PIN_TX);  
}

void loop()
{
    vw_send(SECRET_CODE, sizeof(SECRET_CODE));  
    vw_wait_tx(); // Wait until the whole message is gone

    delay(TX_DELAY); // Don't flood the remote with messages
}

And then try this exact code (if it compiles smiley ) on the client:
Connect an LED to pin 4 on the ATTiny85. If it all works, you should see the LED blink once, then twice and then three times.

Let us know if that works.

Code:
#include <VirtualWire.h>

#define PIN_RX          2
#define PIN_RELAY       3
#define PIN_LED         4
#define BUFFER_LENGTH   30
#define VW_SPEED        2000

static uint8_t buf[BUFFER_LENGTH];    
static uint8_t buflen;

static const char SECRET_CODE[] = { 0x01, 0x02, 0x03 };

void setup()
{
    pinMode(PIN_LED, OUTPUT);
    pinMode(PIN_RELAY, OUTPUT);

    digitalWrite(PIN_RELAY, HIGH);

    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(VW_SPEED);
    vw_set_rx_pin(PIN_RX);
    vw_rx_start();
}

void blink(uint8_t i)
{
    while(i--)
    {
        digitalWrite(PIN_LED, HIGH);
        delay(250);
        digitalWrite(PIN_LED, LOW);
        delay(250);
    }
    delay(1000);
}

void loop()
{
    buflen = BUFFER_LENGTH;
    if (vw_get_message(buf, &buflen)) // Non-blocking    
    {
        for (int i = 0; i != buflen; ++i)
            blink(buf[i]);

        if (buflen >= sizeof(SECRET_CODE) && memcmp(SECRET_CODE, buf, sizeof(SECRET_CODE)) == 0)        
            digitalWrite(PIN_RELAY, LOW);
    }
}
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1058
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I tried this sketch and it worked.

I have one Attiny85 sending Arduino 1234
In the receiving sketch on the second Attiny85 I use strcmp to compare the received message to my "secret password".

I used the latest vw library, and the example receiver sketch

Ofcource you will have to remove all the debugging prints, and use blinking LED's if that is what you want.

Code:
// 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>
#include <TinyDebugKnockBang.h>


char buffer[13];
void setup()
{
  Debug.begin( 250000 ); // Debugging only
  Serial.println("s");

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(3);
  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

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

    sprintf (buffer, "%s" , buf);


    int a=strcmp(buffer, "Arduino 1234");

    Debug.println(a);    
    if (a==0){
      Debug.println("OK");
    }
  }
}
« Last Edit: September 06, 2013, 12:14:23 pm by Erni » Logged

Offline Offline
God Member
*****
Karma: 25
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you have good musical pitch you can get it to output tones at different frequencies.

This actually works pretty well.  If you use a program (on your PC) that allows you to choose the frequency of a tone, and you put that in one ear, you can put the target frequency in the other ear and determine within 1 Hz pretty easily.

You could record the sequence and analyze it on a PC.  Or post it and analyze it on another PC.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,
sorry for not replying, im not getting emails about new posts anymore.

I will try the hardcode of 8 for size of code.

I would prefer not to change the sender (mainly as it is soldered in place and the attiny85 pins are well getting loose).

I will let you know how I go. i hope it works smiley

as i side note, i have realised atmel has a 433mhz transmitter with built in attiny44 all in a 5x5 mm surface mount QFN24. has anyone used these? if i could get the sender to that size instead of attiny85 and my 433mhz transmitter i would be over the moon. ps i have one for testing that Atmel sent me but no way to well use it lol
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried what i can and its not working.

this is the code i have now, i have tried everything in the password section even what the arduino used to pick up with no luck

Code:
#include <VirtualWire.h>

#define PIN_RX          2
#define PIN_RELAY       3
#define BUFFER_LENGTH  50

static uint8_t buf[BUFFER_LENGTH];   
static uint8_t buflen;
static char SECRET_CODE[] = "Benson14";

void setup()
{
    digitalWrite(PIN_RELAY, HIGH);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);      // Bits per sec
    vw_set_rx_pin(PIN_RX);
    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    buflen = BUFFER_LENGTH;
    if (vw_have_message()){
    if (vw_get_message(buf, &buflen)) // Non-blocking   
    {
       digitalWrite(4,HIGH);
        if (memcmp(SECRET_CODE, buf, sizeof(SECRET_CODE)) == 0)
        {
            digitalWrite(PIN_RELAY, LOW);
        }
    }digitalWrite(4,LOW);
    }
}
Logged

Offline Offline
God Member
*****
Karma: 25
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this and see what the receiver thinks the buflen is:

Code:
void loop()
{
    buflen = BUFFER_LENGTH;
    if (vw_have_message()){
    if (vw_get_message(buf, &buflen)) // Non-blocking   
    {
      for (int i = 0; i < buflen; ++i)
      {
        digitalWrite(4,HIGH);
        delay(250);
        digitalWrite(4, LOW);
        delay(250);
      }
        if (memcmp(SECRET_CODE, buf, sizeof(SECRET_CODE)) == 0)
        {
            digitalWrite(PIN_RELAY, LOW);
        }
    }digitalWrite(4,LOW);
    }
}

Then try this to see how far it gets before it finds a mismatch:


Code:
void loop()
{
    buflen = BUFFER_LENGTH;
    if (vw_have_message()){
    if (vw_get_message(buf, &buflen)) // Non-blocking   
    {
      for (int i = 0; i < sizeof(SECRET_CODE); ++i)
      {
        if (buf[i] != SECRET_CODE[i])
        {
          for (int j = 0; j <= i; ++j)
          {
            digitalWrite(4,HIGH);
            delay(250);
            digitalWrite(4, LOW);
            delay(250);
          }
          break;
        }
      }
        if (memcmp(SECRET_CODE, buf, sizeof(SECRET_CODE)) == 0)
        {
            digitalWrite(PIN_RELAY, LOW);
        }
    }digitalWrite(4,LOW);
    }
}

That will blink the index (1-based) of the first letter that doesn't match.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Thank you so much for your reply.

OK so the first lot of code i ran a few times and it was 8 blinks.

the second code does blink at all???
Logged

Offline Offline
God Member
*****
Karma: 25
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the second code doesn't blink at all, that would seem to indicate that it is receiving the correct data.  But if that is the case, why doesn't the memcmp() return a 0?

Try changing the SECRET_CODE to "Benson41" and see if it blinks 7 times.
Logged

Pages: 1 [2]   Go Up
Jump to: