Physical Computing

Readings

Links

Arduino.cc Links

Class Websites



















(:source lang=arduino_cpp :)[@
image upload pmwiki-2.2.106, 2002106

 edit SideBar

Log out

Devices/JNSimpleSend

JeeNode Simple Send and Receive

SimpleSend

SimpleSend and SimpleReceive are minimal sketches for sending from one JeeNode to another. They can be used to "prove out" newly built and configured JeeNodes.

Make sure to confirm that the pin numbers and radio parameters in the sketches agree with the ones you are actually using. Note the the data in the first SimpleSend sketch is hardwired and doesn't change. It is just used to test the radio link.

/* JN_SimpleSend, transmitter side. Test transmission by sending some data
*  Sketch to send some arbitrary data to test JeeNode transmission
*  Put this sketch on a JeeNode with a portable (battery) power supply
*  updated 6-4-2012 by Paul Badger from code by <jcw@equi4.com>
*  http://opensource.org/licenses/mit-license.php
*
*/


#include <JeeLib.h>

byte seqnum;

// the variables below are just "hardwired" data to send
// later we will read a sensor and put some real data into the variables
static int myInt1 = 23;    // "hardwired" data just to test radio transmission
static int myInt2 = 57;    // "hardwired" data just to test radio transmission

void setup() {
        rf12_initialize(20, RF12_433MHZ, 212); // init the radio

                   // params are byte nodeId, byte freqBand, byte netGroup
                   // freqBands  should be RF12_915MHZ, or RF12_433MHZ
                   // nodeId parameter should be in range of to 1-26
                   // netGroup parameter should be in range of to 1-212
                   // red dots on JeeNode radios are 915Mhz, green dots are 434 Mhz
}

void loop() {
        delay(300);

        int buf[3]; // to send more data, just increase the array for each int
        // the first number "seqnum" is just a marker which can be used to see
        // if if transmissions are being received in a sequential manner
        // just counts from 0 to 255 because the variable is declared as a byte

        buf[0] = ++seqnum;

        // now we send our "hardwired" data
        buf[1] = myInt1;
        buf[2] = myInt2;


        while (!rf12_canSend())     // wait until sending is allowed
                rf12_recvDone();    // processes any incoming data
                                    // it all happens "in the background"

        rf12_sendStart(0, buf, sizeof buf);  // sends the data out
  }

SimpleSend with Light Sensor

Adds an LDR light sensor - make sure to confirm pin numbers and radio parameters agree with the ones you are using.

Setup: Add an LDR photocell between ground and A1, (which is the AIO pin on port 2 of a JeeNode).

/* JN_SimpleSend combined with an Light Dependent Resistor. Sends light data to another node.
 *  http://opensource.org/licenses/mit-license.php
 *
 * Hardware Setup:
 * LDR photocell - between Ground & AIO on JeeNode Port 2 (Arduino A1 pin)
 */


#include <JeeLib.h>

int seqnum;

// after you get this working try adding on some more data to send
static int myInt1 = 23;      // random data just to test
static int myInt2 = 57;      // random data just to test


void setup() {
    rf12_initialize(20, RF12_433MHZ, 68);
    // params are byte nodeId, byte freqBand, byte netGroup
    // freqBands  should be RF12_915MHZ, or RF12_433MHZ
    // nodeId parameter should be in range of to 1-26
    // nodeId parms should different on send and receive units
    // netGroup parameter should be in range of to 1-212
    // netGroup param should be the same on send and receiv units
    // red dots on radios are 915Mhz, green dots are 434 Mhz

    Serial.begin(57600);

    // turn on pullup for LDR
    digitalWrite(A1, HIGH);  // A1 is AIO Port 2

}

void loop() {
    delay(30);
    int buf[3];
    buf[0] = ++seqnum;
    buf[1] = analogRead(A1);   // reads sensor and inserts the light data
    Serial.print(buf[0]);
    Serial.print(" ");
    Serial.println(buf[1]);
    buf[2] = myInt2;


    while (!rf12_canSend())    // wait until sending is allowed
            rf12_recvDone();   // process any incoming data (in the background)

    rf12_sendStart(0, buf, sizeof buf);  // send out our data
}
 

JN_SimpleReceive

Make sure to confirm pin numbers and radio parameters agree with the ones you are using


// JN_SimpleReceive.pde   Illustrates receiving data from JN_SimpleSend.pde
// updated 6-4-2012 by paul badger from code by <jcw@equi4.com>
// http://opensource.org/licenses/mit-license.php
// Sketch to receive data from SimpleSend

#include <JeeLib.h>

void setup() {
        Serial.begin(57600);
        Serial.println("\n[simpleReceive]");
        rf12_initialize(18, RF12_433MHZ, 212); // params are byte nodeId, byte freqBand, byte netGroup
                                               // freqBands  should be RF12_915MHZ, or RF12_433MHZ
                                               // nodeId parameter should be in range of to 1-26
                                               // netGroup parameter should be in range of to 1-212

                                               // red dots on radios are 915Mhz, green dots are 434 Mhz
       Serial.print("SimpleReceive");
}

void loop() {
        // rf12_recvDone() is true if new information has been received.
        // re12_crc == 0 indicates good transmission, checks validity of data

        if (rf12_recvDone() && rf12_crc == 0) {  // received good data if true




            int* buf = (int*) rf12_data;       // buf is a pointer to our data
                                               // the same as an array name

                Serial.print(buf[0]);          // this is the sequence number
                Serial.print("  ");            

         // the sequence number is entirely optional but it could be used to
         // see if transmissions are being missed

                Serial.print(buf[1]);          // first "int" of our data
                Serial.print("  ");
                Serial.println(buf[2]);        // second "int" of our data

    }
}
Edit - History - Recent Changes - Search
Page last modified on August 25, 2014, at 06:00 PM