User avatar
kelav
Posts: 17
Joined: Fri Jul 06, 2012 10:54 pm
Location: Montpellier (France)
Contact: Website

ArduinoCommand - Raspberry PI --> Arduino

Thu Dec 06, 2012 10:50 am

EDIT: Just discovered rc-switch which is really great to do this
http://code.google.com/p/rc-switch/
Here is a example of what can be done with it.
http://www.youtube.com/watch?v=TlHfjvLdaBA


I'm working on an easy and cheap method to communicate between an Arduino and an Raspberry PI

The code is everything but pretty, still it works pretty well and it is very easy to modify to suit your needs.

For now, you can only control Digital Pins of Arduino with the Raspberry PI, but i will be working on a way to sends sensor informations to the Raspberry PI.

You just need an 433.92Mhz emitter (on the pi) and an 433.92Mhz receiver (on the Arduino)
It costs me 6€ (for the two).

How to make it works:
Arduino side

Code: Select all

#include <Piwi.h>
//Initialize Piwi with Receiver Data Pin on Digital Pin 2
Piwi piwi(2);

void setup()
{
}

void loop()
{
// Listen for Rpi
  piwi.listen();
}
Raspberry PI (This example put Digital Pin 6 to HIGH)

Code: Select all

./ardwl_cs.sh 6 1
You can download the arduino librairy and Raspberry PI commands here:
https://github.com/maditnerd/433wireles ... z?raw=true

You just have to extract the arduino part in arduino/librairies and to copy the Raspberry PI part anywhere you want on the Rpi. (There is an example in the arduino library)

The git hub is here:
https://github.com/maditnerd/433wirelessPI

An old version running (Code was really improved)
https://www.youtube.com/watch?v=YRHWZOO ... re=g-all-u

EDIT:
How it works (disregard what said in the video)

When you send the number 6 on the raspberry PI it will sends 65 times octets of 1 (11111111)

Why 65 times ? So we are sure the message was correctly transmit even if the arduino received 63 times the messages or 61 times, it will undestand 6.

The bash script just sends two times a message.
If you want to send just an number use arduino_wireless number

If you want to use the information sends for others purpose you will have to modify the library (or ask me to do it).
Last edited by kelav on Wed May 15, 2013 12:15 pm, edited 1 time in total.
Take a look at my wiki on the Raspberry Pi : http://madnerd.org

User avatar
kelav
Posts: 17
Joined: Fri Jul 06, 2012 10:54 pm
Location: Montpellier (France)
Contact: Website

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Fri Dec 07, 2012 2:48 pm

Spend the night trying to do the reverse (Send a message from Arduino to Raspberry PI) but it was clear that it will miserably fail.

The raspberry PI is not real-time so the message is not read as I want (Even with a very large margin of error).
Take a look at my wiki on the Raspberry Pi : http://madnerd.org

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Tue Dec 18, 2012 4:54 pm

Hi,

I have a 433Mhz receiver hooked up to a Pi and can intercept the 24 bit control codes used by my remote control mains sockets. The data is encoded in the width of the pulses, 300uSec for a zero and 900uSec for a one. The starts of the pulses are always 1200uSec apart.

Let me know if you want the source, I don't have it with me at the moment.

Regards,
Geoff.

User avatar
kelav
Posts: 17
Joined: Fri Jul 06, 2012 10:54 pm
Location: Montpellier (France)
Contact: Website

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Tue Dec 18, 2012 5:38 pm

I would be really interested thank you!

I also like to thank you for your contribution on Magpi, it really help me out to works on this and to do my own home automation code with SCS outlet
http://forum.snootlab.com/viewtopic.php?f=46&t=767 (french)
https://github.com/maditnerd/433wirelessPI
Take a look at my wiki on the Raspberry Pi : http://madnerd.org

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Dec 19, 2012 2:06 pm

Here goes. I'm not sure how much I can paste into this forum.

Code: Select all

// g++ -o in rfin.cpp -lwiringPi -lrt
// use the line above to compile this.

#define MINCYCLE 1000000
#define MAXCYCLE 1600000
#define THRESHOLD 600000

#include <wiringPi.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
        int times[10000];
        int timeIndex = 0;

        char bits[100];
        int bitIndex = 0;
        int loToHiTime;
        int hiToLoTime;

        timespec t,sleepTime;
        sleepTime.tv_sec = 0;
        sleepTime.tv_nsec = 100000;

        int currentTime = 0;

        char temp[100];

        int missedLoToHi = 0;
        int missedHiToLo = 0;
        int wrongTime = 0;

        int pin = 8;
        wiringPiSetupSys();

        pinMode (pin, INPUT);

        sprintf(temp, "gpio edge %d both",pin);
        printf("%s\n",temp);

        system(temp);


        bitIndex = 0;
        memset(bits,0,100);

        waitForInterrupt(pin, 1000);
        while (!digitalRead(pin) == 0)
        {
                waitForInterrupt(pin, 1000);
                clock_gettime(CLOCK_MONOTONIC, &t);
        }

        while (1)
        {
                loToHiTime = t.tv_nsec;
                waitForInterrupt(pin, 1000);
                clock_gettime(CLOCK_MONOTONIC, &t);
                if (nanosleep(&sleepTime,NULL))
                {
                         printf("Sleep error\n");
                }
                if (digitalRead(pin))
                {
                        bitIndex = 0;
                        missedHiToLo ++;
                }
                else
                {
                        hiToLoTime = t.tv_nsec;

                        waitForInterrupt(pin, 1000);
                        clock_gettime(CLOCK_MONOTONIC, &t);
                        nanosleep(&sleepTime,NULL);
                        if (!digitalRead(pin))
                        {
                                missedLoToHi ++;
                                bitIndex = 0;
                                while (!digitalRead(pin))
                                {
                                        waitForInterrupt(pin, 1000);
                                        clock_gettime(CLOCK_MONOTONIC, &t);
                                }
                        }
                        else
                        {
                                int totalTime = t.tv_nsec - loToHiTime;
                                if (totalTime < 0)
                                {
                                        totalTime += 1000000000;
                                }

                                if (totalTime < MINCYCLE || totalTime > MAXCYCLE)
                                {
                                        wrongTime++;
                                        bitIndex = 0;
                                }
                                else
                                {
                                        // probably a valid bit.
                                        int hiDuration = hiToLoTime - loToHiTime;
                                        if (hiDuration < 0)
                                        {
                                                hiDuration += 1000000000;
                                        }

                                        if (hiDuration > THRESHOLD)
                                        {
                                                bits[bitIndex]= '1';
                                        }
                                        else
                                        {
                                                bits[bitIndex]= '0';
                                        }
                                        bitIndex ++;

                                        if (bitIndex == 24)
                                        {
                                                //printf("Missed L->H:%d    Missed H->L:%d    Wrong Time:%d\n", missedLoToHi, missedHiToLo, wrongTime);
                                                missedLoToHi = missedHiToLo = wrongTime = 0;
                                                bits[bitIndex] = '\0';
                                                system("date");
                                                printf("%s\n",bits);
                                                printf("\n");
                                                fflush(stdout);
                                                bitIndex = 0;

                                                sleep(60);
                                        }
                                }
                        }
                }
        }
        return 0;
}

This code uses the wiringpi library to access the GPIO. It basically waits for the pin transition interrupts and checks the times of them to determine if it looks like a valid bit, and if so whether it's a 1 or 0. After a string of 24 valid bits, it prints it out with a timestamp. There's a one minute sleep to avoid filling the logs with masses of pointless data.

All questions, improvements, and interesting uses are welcome.

Geoff.

facebraker
Posts: 7
Joined: Sat Jan 19, 2013 6:30 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 06, 2013 3:34 pm

Hi Geoff,

thanks for your code, you rescue my day ;-)

can you explain to me why you are use the wiringPi-Pin 8?
On these scheme is wiringPi-Pin8 SDA0? is this correct?
https://projects.drogon.net/raspberry-pi/wiringpi/pins/


Can i use other Pins, e.g. wiringPi-Pin 1 ist GPIO1 (BCM 18) ?
I do not understand what is SDA0?

Thank you for your help.

Greets Alex

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 06, 2013 5:58 pm

facebraker wrote:Hi Geoff,

thanks for your code, you rescue my day ;-)

can you explain to me why you are use the wiringPi-Pin 8?
On these scheme is wiringPi-Pin8 SDA0? is this correct?
https://projects.drogon.net/raspberry-pi/wiringpi/pins/


Can i use other Pins, e.g. wiringPi-Pin 1 ist GPIO1 (BCM 18) ?
I do not understand what is SDA0?

Thank you for your help.

Greets Alex
I used the generic gpio numbering, rather than the wiringpi numbering. The interrupts only work in this mode. wiringPiSetupSys sets the numbering scheme this way.

I just used pin 8 because it was convenient for me. Any pin should be fine.

Geoff.

facebraker
Posts: 7
Joined: Sat Jan 19, 2013 6:30 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 06, 2013 6:37 pm

Hi Geoff,

Thank you for the quick reply!
One question, your Pin 8 which Pin is that on the raspberry :?: ?
Is the same like the raspberry numbering?
In the moment i dont understand which Pin is use?
Can you please explain me, based on the hyperlink in my last post?
Or you say the Pin 8 on the rasperry-board is my your Pin 8.

Sorry for my bad english!

Thank you for your help.

Alex

facebraker
Posts: 7
Joined: Sat Jan 19, 2013 6:30 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 06, 2013 7:03 pm

Hello,

Maybe you can make a Photo?

Greets Alex

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 06, 2013 9:17 pm

Hi,

I followed the pin numbers on here. It's labelled GPIO 8.

http://elinux.org/RPi_Low-level_peripherals

I think Gordon on the wiringpi page refers to them as the broadcom pin numbers, but just follow the picture in that link and it should work.

I'm already using pin 7 for my 433MHz transmitter, so it made sense for me to use the next one in line.

I don't think a photo would clarify it, the ribbon cable hides everything you'd need to see.

Geoff.

facebraker
Posts: 7
Joined: Sat Jan 19, 2013 6:30 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Thu Feb 07, 2013 10:11 am

Hello Geoff,

thanks for your patience, now I understand it.
I hope I can test it today or tomorrow.

Thanks for your help.

Greets Alex

tobie123
Posts: 73
Joined: Mon Jan 07, 2013 10:41 am

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Fri Feb 08, 2013 9:38 am

Hello,
I have a wireless temperature probe (433MHz)
With my raspberry I try to retrieve the temperature but sometimes I can not may be due to real time, more over my code is blocking any execution on my raspberry

Code: Select all

//valuebuffer, todo: move to external file
#include <wiringPi.h>
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <sched.h>
#include <sstream>
#include <ctime>
#include <mysql/mysql.h>

using namespace std;
typedef unsigned short recordtype;
 struct timeval tbegin;

//initialisation du pin de reception
int pin;

//Fonction de log
void log(string a){
	//Décommenter pour avoir les logs
	cout <<	a << endl;
}

//Fonction de conversion long vers string
string longToString(long double mylong){
    string mystring;
    stringstream mystream;
    mystream << mylong;
    return mystream.str();
}

//Fonction de passage du programme en temps réel (car la reception se joue a la micro seconde près)
void scheduler_realtime() {
	struct sched_param p;
	p.__sched_priority = sched_get_priority_max(SCHED_RR);
	if( sched_setscheduler( 0, SCHED_RR, &p ) == -1 ) {
	perror("Failed to switch to realtime scheduler.");
	}
}

//Fonction de remise du programme en temps standard
void scheduler_standard() {
	struct sched_param p;
	p.__sched_priority = 0;
	if( sched_setscheduler( 0, SCHED_OTHER, &p ) == -1 ) {
	perror("Failed to switch to normal scheduler.");
	}
}

//Recuperation du temp (en micro secondes) d'une pulsation
int pulseIn(int pin, int level, int timeout)
{
   struct timeval tn, t0, t1;
   long micros;
   gettimeofday(&t0, NULL);
   micros = 0;

stringstream ss;
ss << digitalRead(pin);
log(ss.str());
   while (digitalRead(pin) != level)
   {
      gettimeofday(&tn, NULL);
      if (tn.tv_sec > t0.tv_sec) micros = 1000000L; else micros = 0;
      micros += (tn.tv_usec - t0.tv_usec);
      if (micros > timeout) return 0;
   }
   gettimeofday(&t1, NULL);
   while (digitalRead(pin) == level)
   {
      gettimeofday(&tn, NULL);
      if (tn.tv_sec > t0.tv_sec) micros = 1000000L; else micros = 0;
      micros = micros + (tn.tv_usec - t0.tv_usec);
      if (micros > timeout) return 0;
   }
   if (tn.tv_sec > t1.tv_sec) micros = 1000000L; else micros = 0;
   micros = micros + (tn.tv_usec - t1.tv_usec);
   return micros;
}

 


template <class storageType>
class ValueBuffer
{
   public:
      ValueBuffer(const int bufferSize,const storageType initValue=0);
      ~ValueBuffer();
      void operator<<(const storageType input);
      storageType operator[](int wantedN) const;
      void reset(int resetValue);

   private:
      const int _bufferSize;
      storageType* _buffer;
      int _bufferIndex;
};

template <class storageType> 
ValueBuffer<storageType>::ValueBuffer(const int bufferSize,const storageType initValue)
   : _bufferIndex(0), _bufferSize(bufferSize)
{
  _buffer = (storageType*)calloc(bufferSize,sizeof(storageType));
   for(int i=0; i < bufferSize; i++)
      _buffer[i] = initValue;
   
}
template <class storageType> 
ValueBuffer<storageType>::~ValueBuffer()
{
  free(_buffer);
}
template <class storageType> 
void ValueBuffer<storageType>::operator<<(const storageType input)
{
   _buffer[_bufferIndex] = input;
   if (_bufferIndex == _bufferSize - 1)
   {
      _bufferIndex = 0;
   }
   else
   {
      ++_bufferIndex;
   }
}
template <class storageType> 
void ValueBuffer<storageType>::reset(int resetValue)
{
   for(int i=0; i < _bufferSize; i++)
      _buffer[i] = resetValue;
}

template <class storageType> 
storageType ValueBuffer<storageType>::operator[](const int wantedN) const
{
   int index = _bufferIndex-1;
   if(index - wantedN >= 0)
   {
      return _buffer[index-wantedN];
   } 
   else 
   {
      return _buffer[index-wantedN+_bufferSize];
   }
}


//todo: move temperature to external file/class

//-4.8:010000010010000001000011000
struct temperatureData {
   unsigned char checksum     : 4;
   unsigned char thirdNumber  : 4;
   unsigned char secondNumber : 4;
   unsigned char firstNumber  : 3;
   unsigned char padding      : 1; // not used, could be used for a "-" boolean in the future
};


#define IS_IN_RANGE(var,min,max)     (var>min&&var<max)
#define IS_HIGH_PULSE(var)           IS_IN_RANGE(var,1250,1600)
#define IS_LOW_SHORT_PULSE(var)      IS_IN_RANGE(var,150,540)
#define IS_LOW_LONG_PULSE(var)       IS_IN_RANGE(var,1800,2400)
#define SET_BIT(var,bitnum)   (*((unsigned long*)&var) |= 1 << bitnum)
#define CLEAR_BIT(var,bitnum) (*((unsigned long*)&var) &= ~(1 << bitnum))

//new buffer with 110 items, fill with 0's
ValueBuffer<recordtype> recording(110,0);
int nb_occ;
void checkTemp()
{
  if(recording[0] > 45000)
  {
     if(IS_HIGH_PULSE(recording[1]) && 
        IS_LOW_SHORT_PULSE(recording[2]) &&
        IS_HIGH_PULSE(recording[3]))
     {
log(longToString(recording[0]));
       int bitCount=0;
       struct temperatureData receivedTemperature;
       
       //log("pn");
       //parse the data(from the last pulse to the first pulse)
       for(int i=4;i<=107-15;i+=2) //+2: skip the highs since high pulses don't differ in length
       {
           if(IS_LOW_LONG_PULSE(recording[i]) && !IS_LOW_SHORT_PULSE(recording[i+2]))
           {
             log("0");
             CLEAR_BIT(receivedTemperature,bitCount);
             bitCount++;
           }
           else if(IS_LOW_LONG_PULSE(recording[i]) && 
             IS_LOW_SHORT_PULSE(recording[i+2]) &&
             IS_LOW_SHORT_PULSE(recording[i+4]) )
           {
             log("1");
             SET_BIT(receivedTemperature,bitCount);             
             bitCount++;
             i+=4;
           }
           else
           {
             log("DC");
             log(longToString(recording[i])+" - "+longToString(i)+" - "+longToString(bitCount));
             return;
           }
           if(bitCount == 15) // we got all the bits (was 15)
           {

		string tempe = "";

        string str_fts = "fts: ";
        str_fts = str_fts + (IS_HIGH_PULSE(recording[1])?"g":"f" );
        str_fts = str_fts + (longToString(recording[1]));
        str_fts = str_fts + (IS_LOW_SHORT_PULSE(recording[2])?"g":"f");
        str_fts = str_fts + (longToString(recording[2]));
        str_fts = str_fts + (IS_HIGH_PULSE(recording[3])?"g":"f"); 
        str_fts = str_fts + (longToString(recording[3]));
	nb_occ = nb_occ +1;
	log  (str_fts );
time_t temps_act;
time(&temps_act);
log(ctime(&temps_act));
              log("");
              if(IS_LOW_SHORT_PULSE(recording[i+8]))
                log("-");
		tempe =tempe + "-";
              if(receivedTemperature.firstNumber)
		log(longToString((int)receivedTemperature.firstNumber));                  
		log(longToString((int)receivedTemperature.secondNumber));  
		log(".");           
		log(longToString((int)receivedTemperature.thirdNumber));	
		

		/*tempe = longToString((int)receivedTemperature.firstNumber) +"" +longToString((int)receivedTemperature.secondNumber)+"."+longToString((int)receivedTemperature.thirdNumber);
		
		time_t now;
		char *mon_temps;
		mon_temps= ctime(&now);
		
	

		sleep(224)   ;
              return;
           }           
       }
     } else { //some debugging to adjust the signal timing
        /*string str_fts = "fts: ";
        str_fts = str_fts + (IS_HIGH_PULSE(recording[1])?"g":"f" );
        str_fts = str_fts + (longToString(recording[1]));
        str_fts = str_fts + (IS_LOW_SHORT_PULSE(recording[2])?"g":"f");
        str_fts = str_fts + (longToString(recording[2]));
        str_fts = str_fts + (IS_HIGH_PULSE(recording[3])?"g":"f"); 
        str_fts = str_fts + (longToString(recording[3]));
	nb_occ = nb_occ +1;

	if (nb_occ == 60){
		nb_occ = 1;	
	}
	log  (str_fts+" -- "+longToString(nb_occ));*/
     	/*if (nb_occ == 58)
	{
	 usleep (500000);
	}   */
        
       /*for(int i=110;i>=0;i--) 
       {
         log(recording[i]); 
       }*/

     }
  }
}

void interruptHandler()
{
  static recordtype previousTime=0;
  recordtype currentTime = micros();
  recordtype difference = currentTime-previousTime;
  
  if(difference < 100) //filter noise, received signals should never be shorter than 100(in this case...)
    return;
  
  recording << difference;

  previousTime = currentTime;
  //digitalWrite(LEDPIN,digitalRead(2));
  checkTemp();
}

int main (int argc, char **argv)   
{
	pin = 5;
	//On passe en temps réel
	scheduler_realtime();
	
	
	log("Demarrage du programme");
	// initialisation 

	


	//Si on ne trouve pas la librairie wiringPI, on arrête l'execution
    if(wiringPiSetup() == -1)
    {
        log("Librairie Wiring PI introuvable, veuillez lier cette librairie...");
        return -1;
    }else{
    	log("Librairie WiringPI detectee");
    }
/*    pinMode(pin, INPUT);*/
	log("Pin GPIO configure en entree");
    log("Attente d'un signal du transmetteur ...");
  //interrupt for receiving the data, connect receiver to pin 2
	int status_pin_prec;
	for (;;){
		/*  attachInterrupt(0, interruptHandler, CHANGE);*/
		if (digitalRead(pin) != status_pin_prec )
		{
			status_pin_prec = digitalRead(pin);
			interruptHandler();
		}
  	}

    
   /*Serial.begin(115200);*/
   log("Ready");
}

void loop() {
}

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Feb 13, 2013 9:32 pm

I see you are using a loop to wait for the input signal. Take a look at the wiring pi library for code to do this using interrupts. Doing it that way uses about ten percent of my CPU. I find I reliably receive 24 bit codes from my radio controlled sockets and from some PIR sensors I have.

leonardo
Posts: 9
Joined: Sun Dec 30, 2012 3:30 pm
Location: Italy, not my fault, I wasn't able to deceide where to born

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Thu Feb 14, 2013 4:41 pm

Hello I'm trying Geoff's code but at the moment I cannot get any data... I have several devices that send signal on 433MHz and I'll try more this evening at home.
Right now I tested it with no output at all except the initial message: gpio edge 8 both
At the moment I tryied with some devices (anti intrusion door sensors) and a couple of remotes like this:
Image

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Thu Feb 14, 2013 6:40 pm

It may be better to just print out the input value in a tight loop for a hundred thousand loops or so. Do that while pressing the remote button and see if you get groups of 1s and 0s rather than just random stuff.

If that works, try to figure out the code to time how long it pulses for.

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Fri Feb 15, 2013 7:36 am

Here's my code to dump out the time spent in the high and low states. From this, you can estimate the timing values needed in the reading code.

Code: Select all

// g++ -o dumptimes dumptimes.cpp -lwiringPi -lrt
#include <wiringPi.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	// prepare a buffer to store things.
        int times[10000];
        int timeIndex = 0;

	// set up the GPIO
        timespec t;
        int lastTime = 0;

        char temp[100];

        int pin = 11;//8;
        wiringPiSetupSys();

        pinMode (pin, INPUT);

        sprintf(temp, "gpio edge %d both",pin);
        printf("%s\n",temp);

        system(temp);

	// wait to start on a 1 input.
        while (digitalRead(pin) == 0)
        {
                waitForInterrupt(pin, 1000);
        }

	// main loop
        while (timeIndex < 10000)
        {
		// get the time immediately after a pin state change
                waitForInterrupt(pin, 1000);
                clock_gettime(CLOCK_MONOTONIC, &t);

                // make sure we have the high in the even numbered entries in our array
		if (digitalRead(pin) && timeIndex%1)
                {
                        times[timeIndex] = 0;
                        timeIndex ++;
                }

		// store the elapsed time in the array
                int elapsed = t.tv_nsec - lastTime;
                times[timeIndex++] = elapsed;

		// give up if something doesn;t look right.
                if (elapsed < 0)
                {
                        break;
                }
                lastTime = t.tv_nsec;
        }

	// now loop through the array, dumping out the high and low times
        for (int i = 0 ; i < timeIndex ; i+=2)
        {
                printf("H%d ",times[i] / 1000);
                printf("L%d ",times[i+1] / 1000);
        }

        printf("\n");
        return 0;
}

leonardo
Posts: 9
Joined: Sun Dec 30, 2012 3:30 pm
Location: Italy, not my fault, I wasn't able to deceide where to born

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Fri Feb 15, 2013 8:39 am

Thanks it works!
I can read the timing of single bit and pressing the same button on the remote I have "compatible" values. Obviously they are not exactly the same, but it makes sense!

codedmind
Posts: 4
Joined: Thu Feb 21, 2013 8:57 am

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Thu Feb 21, 2013 8:17 pm

In the code when you set pin = 8;
Is because you have rfm12 SS in GPIO 8 (CE0) ?

If that is correct if i have the following scenario
Image

And change pin = 8; to pin = 7; i should be able to receive some data from a remote device?

Thanks

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Thu Feb 21, 2013 10:41 pm

Hi,

I think the rfm12 is a much more complex device than the one I used. I'm pretty sure the connections aren't as simple as your picture implies.

There are a few threads on the forum discussing that device. The people in those know far more than me on it, so I think you would be better off searching for rfm12 and taking a look at what comes up.

Geoff.

User avatar
moallen
Posts: 36
Joined: Fri Dec 28, 2012 6:37 pm
Contact: Website

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Fri Feb 22, 2013 1:20 am

Geoff:

[quote="Hoagie"]Here's my code to dump out the time spent in the high and low states. From this, you can estimate the timing values needed in the reading code.

Could you be more specific about how to use the dumptime values to adjust your rfin code above?

I'm receiving codes from a Woods Wireless Outlet system sold here in the USA. It is similar to the Status units you used. Your rfin code more or less works ok with my units. There are certain buttons and house codes that will not work, so I think I might need to adjust the timing a little.

I did use Audacity to check the bit timing on my units, and they seem quite close to your system. In fact, if I manually interpret the bits in Audacity, they match exactly on the buttons that do work as shown by rfin.

Without knowing quite what I was doing, I did try different settings for Mincycle Maxcycle and Threshold to no avail.
http://allenmlab.blogspot.com/

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Tue Feb 26, 2013 7:29 am

Hi,

It sounds like the timing is ok if most buttons work. But anyway, here's how to do it.

Run the timing app and press your control button.
Find the area in the output where the numbers seem consistently higher than the rest, this is where the control transmitted.
Copy the data from there into notepad or something similar and add a new line just before each H.
You should easily spot that there are two general times in use and each line has one of each. Maybe a short high and long low, maybe the other way around.
Find the average of the long times and short times. Add these together to get the total time per bit.
Set mincycle and maxcycle to this total, with a bit of leeway for timing errors.
Set threshold to half of the total time.

If you send me the audacity file of the one that's giving you problems, I'll take a look and see what I think things should be. Probably easiest to PM me a dropbox link or something similar if you don't want your remote codes too public. But then again I had mine published in MagPi and no-one's switched my lights off yet.

Geoff.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Mon Mar 18, 2013 12:44 pm

Hi,

I've tried to use the code that Geoff has posted to capture a garage door remote output, with one of the cheap 433.92MHz receivers off ebay, and I'm not getting anything.

It works great for my Status Remote Socket Remote Control. Every button results in some output.

Should the code work for other remotes?

Any ideas how I can capture the signal from the garage door remote?

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: Piwi : 433.92 Mhz Arduino <-> Raspberry PI

Wed Mar 20, 2013 7:32 am

I posted some code on here that just dumps the times between transitions, you may be able to use that to find some better settings for the times in the receiver code. But, it could be a completely different modulation system that my receiver code doesn't work with.

Geoff.

Antivirusvivente
Posts: 130
Joined: Fri Dec 07, 2012 4:01 pm
Location: Bari
Contact: Website

Re: ArduinoCommand - Raspberry PI --> Arduino

Sat Aug 17, 2013 11:29 am

Hello guys, sorry for re-up

I was wondering if this solution is good to do the job:
http://www.ebay.com/itm/1pcs-433Mhz-RF- ... 31824#shId

And I need a place to buy a cheaper Arduino (a StandAlone version could be more convenient to install more and more ATMega chips).

In my Raspberry Domotic system I already use TX and RX pins for a relay controller, how will I connect these things?
DomoHome is coming! - RaspberryPi ~ Raspbian ~ Android
https://www.facebook.com/pages/Domohome/155791057916884

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: ArduinoCommand - Raspberry PI --> Arduino

Sun Aug 18, 2013 12:52 am

Hi,

Those look just like the ones I used. The transmitter is great, but the receiver is not very sensitive.

I found any gpip pin can works fine with these modules, but I worked with custom softwate.

Regards,
Geoff

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 13 guests